<?php
// $Id: album_cat.php 388 2012-05-25 07:58:04Z tomqin@gmail.com $

defined('IN_ADMIN') or exit('Access Denied!');

class Album_Cat_Action extends Action_Admin{

    public function init(){
        parent::init();

        $this->shop_id = intval($this->params);
        $this->setVar('shop_id', $this->shop_id);

        $this->album_cat = App::module('table_album_cat', 'table', array($this->user));
        if(!$this->album_cat->check_user_right($this->shop_id)){
            $this->renderDialog('您无权管理此分类信息！');
        }
    }

    public function onList(){
        $list = $this->album_cat->get_list($this->shop_id);

        $this->setVar('list', $list);
        $this->render('admin/album/cat');
    }

    public function onCreate(){
        $this->setVar('show_validator', 1);
        $this->render('admin/album/cat_edit');
    }

    public function onModify(){
        $this->setVar('show_validator', 1);
        list( , $album_cat) = explode('-', $this->params);

        $data = $this->album_cat->get_data($this->shop_id, intval($album_cat));
        if($data){
            $this->setVar('data', $data);
            $this->render('admin/album/cat_edit');
        }else{
            $this->renderDialog('信息不存在，无法读取信息！');
        }
    }

    public function onDelete(){
        $this->album_cat->delete($this->shop_id, array_get_int($_GET, 'album_cat'));
        $this->renderDialog('删除成功！', '/admin/album_cat/list/'.$this->shop_id);
    }

    public function onSave(){
        if(array_get_bool($_POST, 'dosubmit')){
            $method  = array_get_string($_POST, 'method');

            switch($method){
                case 'create':
                    $_POST['shop_id'] = $this->shop_id;
                    $this->album_cat->insert($_POST);
                    $this->renderDialog('添加成功！', '/admin/album_cat/list/'.$this->shop_id, 'addcat');
                break;
                case 'modify':
                    $this->album_cat->update($this->shop_id, array_get_int($_POST, 'album_cat'), $_POST);
                    $this->renderDialog('添加成功！', '/admin/album_cat/list/'.$this->shop_id, 'editcat');
                break;
                case 'upgrade':
                    $this->album_cat->upgrade($this->shop_id, $_POST);
                    $this->renderDialog('更新成功！', '/admin/album_cat/list/'.$this->shop_id);
                break;
            }
        }else{
            $this->renderDialog('无效的参数！');
        }
    }

    function __destruct(){}
}
?>